<div class="fly-panel fly-column">
  <div class="layui-container">
    <ul class="layui-clear">
      <li class="layui-hide-xs {$cateid == 0 ? 'layui-this' : ''}">
        <a href="{:url('home/index/index')}">全部</a>
      </li>

      {foreach $catelist as $item}
        <li class="{$cateid == $item['id'] ? 'layui-this' : ''}"><a href="{:url('home/index/index',['cateid'=>$item['id']])}">{$item.name}</a></li>
      {/foreach}
      
      <!-- 用户登入后显示 -->
      {if condition="$Think.cookie.LoginUser"}
        <li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block">
          <span class="fly-mid"></span>
        </li>
        <li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block">
          <a href="{:url('home/post/index')}">我发表的贴</a>
        </li>
        <li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block">
          <a href="{:url('home/post/collect')}">我收藏的贴</a>
        </li>
      {/if}
    </ul>
    
    <div class="fly-column-right layui-hide-xs"> 
      <span class="fly-search"><i class="layui-icon"></i></span> 
      <a href="{:url('home/post/add')}" class="layui-btn">发表新帖</a> 
    </div> 

    <div class="layui-hide-sm layui-show-xs-block" style="margin-top: -10px; padding-bottom: 10px; text-align: center;"> 
      <a href="{:url('home/post/add')}" class="layui-btn">发表新帖</a> 
    </div> 
  </div>
</div>

<div class="layui-container">
  <div class="layui-row layui-col-space15">
    <!-- 左侧 -->
    <div class="layui-col-md8">
      <!-- 置顶 -->
      <div class="fly-panel">
        <!-- 移动端 -->
        <div class="fly-panel-title fly-filter">
          <a>置顶</a>
          <a href="#signin" class="layui-hide-sm layui-show-xs-block fly-right" id="LAY_goSignin" style="color: #FF5722;">去签到</a>
        </div>
        <ul class="fly-list">
          {foreach $posttop as $item}
            <li>
              <!-- 头像链接 -->
              <a href="{:url('home/user/index',['userid'=>$item['userid']])}" class="fly-avatar">
                {if condition="$item['user']['avatar']"}
                  <img src="/{$item.user.avatar}" />
                {else /}
                  <img src="/assets/home/images/avatar.jpg" />
                {/if}
              </a>

              <!-- 标题 -->
              <h2>
                <a class="layui-badge">{$item.cate.name}</a>
                <a href="{:url('home/index/info',['postid'=>$item['id']])}">
                  {$item.title}
                </a>
              </h2>

              <div class="fly-list-info">
                <!-- 昵称 -->
                <a href="{:url('home/user/index',['userid'=>$item['userid']])}" link>
                  <cite>{$item.user.nickname}</cite>
                  {if condition="$item.user['auth']>0"}
                    <i class="iconfont icon-renzheng"></i>
                  {/if}
                </a>
                <!-- 发布时间 -->
                <span>{$item.createtime}</span>
                
                <!-- 积分数 -->
                <span class="fly-list-kiss layui-hide-xs" title="悬赏积分">
                  <i class="iconfont icon-kiss"></i> {$item.point}
                </span>

                {if condition="$item.accept"}
                  <span class="layui-badge fly-badge-accept layui-hide-xs">已结</span>
                {/if}

                <!-- 评论数 -->
                <span class="fly-list-nums"> 
                  <i class="iconfont icon-pinglun1" title="回答"></i> {$item.comment}
                </span>
              </div>

              <!-- 帖子状态 -->
              {if condition="$item.state eq 1"}
                <div class="fly-list-badge">
                  <span class="layui-badge layui-bg-red">置顶</span>
                </div>
              {elseif condition="$item.state eq 2" /}
                <div class="fly-list-badge">
                  <span class="layui-badge layui-bg-green">精华</span>
                </div>
              {elseif condition="$item.state eq 3" /}
                <div class="fly-list-badge">
                  <span class="layui-badge layui-bg-black">热门</span>
                </div>
              {/if}
            </li>
          {/foreach}
        </ul>
      </div>

      <!-- 列表结构 -->
      <div class="fly-panel" style="margin-bottom: 0;padding-bottom: 2em;">
        <div class="fly-panel-title fly-filter">
          <a href="{:url('home/index/index',['cateid'=>$cateid])}" class="{$accept === '' ? 'layui-this' : ''}">
            全部
          </a>
          <span class="fly-mid"></span>

          <a class="{$accept === '0' ? 'layui-this' : ''}" href="{:url('home/index/index',['cateid'=>$cateid,'accept'=>0])}">
            未结
          </a>
          <span class="fly-mid"></span>

          <a class="{#accept === '1' ? 'layui-this' : ''}" href="{:url('home/index/index',['cateid'=>$cateid,'accept'=>1])}">
            已结
          </a>
        </div>

        <!-- 帖子列表 -->
        <ul class="fly-list">
          {foreach $postlist as $item}
            <li>
              <!-- 头像链接 -->
              <a href="{:url('home/user/index',['userid'=>$item['userid']])}" class="fly-avatar">
                {if condition="$item['user']['avatar']"}
                  <img src="/{$item.user.avatar}" />
                {else /}
                  <img src="/assets/home/images/avatar.jpg" />
                {/if}
              </a>

              <!-- 标题 -->
              <h2>
                <a class="layui-badge">{$item.cate.name}</a>
                <a href="{:url('home/index/info',['postid'=>$item['id']])}">
                  {$item.title}
                </a>
              </h2>

              <div class="fly-list-info">
                <!-- 昵称 -->
                <a href="{:url('home/user/index',['userid'=>$item['userid']])}" link>
                  <cite>{$item.user.nickname}</cite>
                  {if condition="$item.user['auth']>0"}
                    <i class="iconfont icon-renzheng"></i>
                  {/if}
                </a>
                <!-- 发布时间 -->
                <span>{$item.createtime}</span>
                
                <!-- 积分数 -->
                <span class="fly-list-kiss layui-hide-xs" title="悬赏积分">
                  <i class="iconfont icon-kiss"></i> {$item.point}
                </span>

                {if condition="$item.accept"}
                  <span class="layui-badge fly-badge-accept layui-hide-xs">已结</span>
                {/if}

                <!-- 评论数 -->
                <span class="fly-list-nums"> 
                  <i class="iconfont icon-pinglun1" title="回答"></i> {$item.comment}
                </span>
              </div>

              <!-- 帖子状态 -->
              {if condition="$item.state eq 1"}
                <div class="fly-list-badge">
                  <span class="layui-badge layui-bg-red">置顶</span>
                </div>
              {elseif condition="$item.state eq 2" /}
                <div class="fly-list-badge">
                  <span class="layui-badge layui-bg-green">精华</span>
                </div>
              {elseif condition="$item.state eq 3" /}
                <div class="fly-list-badge">
                  <span class="layui-badge layui-bg-black">热门</span>
                </div>
              {/if}
            </li>
          {/foreach}
        </ul>

        <!-- 帖子分页 -->
        {$pagestr}
      </div>
    </div>

    <!-- 右侧 -->
    <div class="layui-col-md4">
      <!-- 签到 -->
      <div class="fly-panel fly-signin">
        <div class="fly-panel-title">
          今日签到
          {if condition="$signnum"}
            <span class="fly-signin-days">已连续签到<cite>{$signnum}</cite>天</span>
          {else /}
            <span class="fly-signin-days">已连续签到<cite>0</cite>天</span>
          {/if}
        </div>

        <div class="fly-panel-main fly-signin-main">
          {if condition="$signflag == false"}
            <button class="layui-btn layui-btn-danger" id="sign">今日签到</button>
            <span>可获得<cite>5</cite>积分</span>
          {else /}
            <!-- 已签到状态 -->
            <button class="layui-btn layui-btn-disabled">今日已签到</button>
            <span>共获得了<cite>{$signpoint}</cite>积分</span>
          {/if}
        </div>
      </div>

      <!-- 本周精华 -->
      <div class="fly-panel">
        
        <h3 class="fly-panel-title">本周精华</h3>

        <ul class="fly-panel-main fly-list-static">
          {foreach $postelite as $item}
            <li>
              <a href="{:url('home/index/info',['postid'=>$item['id']])}" target="_blank">{$item.title}</a>
            </li>
          {/foreach}
        </ul>
      </div>

      <!-- 本周热议 -->
      <dl class="fly-panel fly-list-one">
        <dt class="fly-panel-title">本周热议</dt>
        {if condition="$posthots"}
          {foreach $posthots as $item}
            <dd>
              <a href="{:url('home/index/info',['postid'=>$item['id']])}">{$item.title}</a>
              <span><i class="iconfont icon-pinglun1"></i> {$item.comment}</span>
            </dd>
          {/foreach}
        {else /}
          <!-- 无数据时 -->
          <div class="fly-none">没有相关数据</div>
        {/if}
      </dl>

      <!-- 回贴周榜 -->
      <div class="fly-panel fly-rank fly-rank-reply" id="LAY_replyRank">
        <h3 class="fly-panel-title">回贴周榜</h3>
        <dl>
          {foreach $grouplist as $item}
            <dd>
              <a href="{:url('home/user/index',['userid'=>$item['id']])}">
                {if condition="$item.avatar"}
                  <img src="/{$item.avatar}" />
                {else /}
                  <img src="/assets/home/images/avatar.jpg" />
                {/if}
                <cite>{$item.nickname}</cite>
                <i>{$item.nums}次回答</i>
              </a>
            </dd>
          {/foreach}
        </dl>
      </div>
    </div>
  </div>
</div>

<script>
  layui.use('layer',function(){
    var layer=layui.layer
    var $=layui.jquery

    // 给删除按钮绑定事件
    $("#sign").on('click',function(){
      // 发送异步请求
      $.ajax({
        url:`{:url('home/index/index')}`,
        type:'post',
        data:'action=sign',
        dataType:'json',
        success:function(success){
          if(success.result){
            layer.msg(success.msg,{
              icon:1,
              time:2000,
            },function(){
              location.reload()
            })
          }else{
            layer.msg(success.msg)
          }
        }
      })
    })
  })

</script>